package com.czmh.etc.onlinepubsys.request.cmg;

import com.alibaba.fastjson.annotation.JSONField;
import com.czmh.etc.common.core.utils.Sequence;
import com.czmh.etc.onlinepubsys.entity.mingchuang.CarInfo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;

/**
 * Copyright (C), 2017-2021
 *
 * @Author Chenzj
 * Date: 2021/3/19 08:22
 * FileName: AddVehicleRequest
 * Description:
 */
@ApiModel("招商局-车辆信息录入-对接请求对象\n" +
        "车型无需提交，系统自动根据输入的座位数或车长+轴数+总质量判断，但界面需显示。\n" +
        "客车车型（座位数+车长）：一型客车：座位数1-9，车长0-5999，二型客车：座位数10-19，车长0-\n" +
        "5999，三型客车：座位数20-39或车长6000及以上，四型客车：座位数40以上\n" +
        "货车车型（车长+轴数+总质量）：一类货车：轴数=2、车长0-5999且总质量1-4499，二类货车：轴数\n" +
        "=2、车长6000及以上或总质量4500及以上，三类货车：轴数=3，四类货车：轴数=4，五类货车：轴数\n" +
        "=5，六类货车：轴数6 \n" +
        "专项作业车车型（车长+轴数+总质量）：一类专项作业车：轴数=2、车长0-5999且总质量1-4499，二\n" +
        "类专项作业车：轴数=2、车长6000及以上或总质量4500及以上，三类专项作业车：轴数=3，四类专项\n" +
        "作业车：轴数=4，五类专项作业车：轴数=5，六类专项作业车：轴数6\n" +
        "车牌为应急车车牌（省份简称+大写字母+4位数字或大写字母+应急）用户类型只能选择26-专用号牌车\n" +
        "用户，使用性质只能为8-应急救援，车牌颜色只能为3-白色，其他车牌不能选择26-专用号牌车用户，8-\n" +
        "应急救援。")
@Data
public class AddVehicleRequest {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("用户ID")
    @JSONField(serialize = false)
    private String userId; //用户ID

    @ApiModelProperty("订单id")
    @JSONField(serialize = false)
    private String orderId; //订单id

    @ApiModelProperty(notes = "车类型,行驶证上的车辆类型", required = true)
    private String carType;

    @ApiModelProperty(notes = "用户类型 0–普通车 24-单用途集装箱车 26-专用号牌车 27-牵引车 28-多用途集装箱车， 24、27、28为货车／专项作业车专用26为专项作业车专用", required = true)
    private Integer cardUserType;

    @ApiModelProperty(notes = "设备编号", required = true, hidden = true)
    private String clientKey;

    @ApiModelProperty(notes = "个人用户编码/经办人编码", required = true)
    private String csUserNo;

    @ApiModelProperty(notes = "证件号码", required = true)
    private String idNum;

    @ApiModelProperty(notes = "证件类型0-身份证； 1-军官证；2-护照；3-港澳通行证；4-台湾通行证5-营业执照；6-组织机构代码证；7-社会团体法人 8-社会信用代码 9-事业单位法人 10-律师事务所许可证", required = true)
    private Integer idType;

    @JSONField(format = "yyyy-MM-dd")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @ApiModelProperty(notes = "发证日期格式：yyyy-MM-dd", required = true)
    private Date issueDate;

    @ApiModelProperty(notes = "整备质量,单位：千克，取值0-16777215", required = true)
    private Integer maintenanceMass = 0;

    @ApiModelProperty(notes = "准牵引总质量,单位：千克，取值0-16777215", required = true)
    private Integer permittedTowWeight = 0;

    @ApiModelProperty(notes = "行驶证图片,图片使用Base64编码字符串，大小不超过300k", required = true)
    private String picData;

    @JSONField(format = "yyyy-MM-dd")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @ApiModelProperty(notes = "注册日期格式：yyyy-MM-dd", required = true)
    private Date registerDate;

    @ApiModelProperty(notes = "时间戳", hidden = true)
    private Long time;

    @ApiModelProperty(notes = "总质量,单位：千克，取值1-16777215", required = true)
    private Integer totalMass;

    @ApiModelProperty(notes = "使用性质0非营运、1营运、8-应急救援", required = true)
    private Integer userType = 0;

    @ApiModelProperty(notes = "轮数,单位：个，取值2-6", required = true)
    private Integer vehicleAxles;

    @ApiModelProperty(notes = "车辆发动机号", required = true)
    private String vehicleEngineNumber;

    @ApiModelProperty(notes = "车高,单位：毫米，取值0-25500", required = true)
    private Integer vehicleHeight;

    @ApiModelProperty(notes = "车长,单位：毫米，取值0-6553500", required = true)
    private Integer vehicleLong;

    @ApiModelProperty(notes = "车牌号", required = true)
    private String vehiclePlate;

    @ApiModelProperty(notes = "车牌颜色,0蓝色、1黄色、2黑色、3白色4、渐变绿色5、黄绿双拼色 6、蓝白渐变色", required = true)
    private Integer vehiclePlateColor;

    @ApiModelProperty(notes = "车辆品牌型号", required = true)
    private String vehicleSpecificInformation;

    @ApiModelProperty(notes = "客货类型：1客车，2货车、3专项作业车", required = true)
    private Integer vehicleType;

    @ApiModelProperty(notes = "核定载重量/座位数,单位：千克（货车／专项作业车）/座（客车），取值1-16777215/1-99", required = true)
    private Integer vehicleWeightLimits;

    @ApiModelProperty(notes = "轴数,单位：个，取值0-255", required = true)
    private Integer vehicleWheels;

    @ApiModelProperty(notes = "车宽,单位：毫米，取值0-25500", required = true)
    private Integer vehicleWidth;

    @ApiModelProperty(notes = "车辆识别代号", required = true)
    private String vin;

    @ApiModelProperty(notes = "轴型")
    private String axisType;

    @ApiModelProperty(notes = "部门")
    private String department;

    @ApiModelProperty(notes = "档案编号")
    private String fileNum;

    @ApiModelProperty(notes = "机动车登记证图片,图片使用Base64编码字符串，大小不超过300k")
    private String picData2;

    @ApiModelProperty(notes = "道路运输证图片,图片使用Base64编码字符串，大小不超过300k")
    private String picData3;

    @ApiModelProperty(notes = "防爆膜")
    private Integer protectFilm;

    @ApiModelProperty(notes = "检验记录")
    private String testRecord;

    @ApiModelProperty(notes = "道路运输证号")
    private String transportNo;

    @ApiModelProperty(notes = "轴距,单位：分米，取值0-65535")
    private Integer vehicleWheelBases;

    public static CarInfo translate(AddVehicleRequest addVehicleRequest) {
        CarInfo vehicle = new CarInfo();
        vehicle.setId(Sequence.getId());
        vehicle.setUserId(addVehicleRequest.getUserId());
        vehicle.setVehPlate(addVehicleRequest.getVehiclePlate());
        vehicle.setVehColor(addVehicleRequest.getVehiclePlateColor());
        vehicle.setType(addVehicleRequest.getVehicleType());
        vehicle.setOwnerIdType(addVehicleRequest.getIdType());
        vehicle.setOwnerIdNum(addVehicleRequest.getIdNum());
        vehicle.setCsUserNo(addVehicleRequest.getCsUserNo());
        vehicle.setVehicleType(addVehicleRequest.getCarType());
        vehicle.setVehicleModel(addVehicleRequest.getVehicleSpecificInformation());
        vehicle.setUseCharacter(addVehicleRequest.getCardUserType());
        vehicle.setVin(addVehicleRequest.getVin());
        vehicle.setEngineNum(addVehicleRequest.getVehicleEngineNumber());
        vehicle.setIssueDate(addVehicleRequest.getIssueDate());
        vehicle.setRegisterDate(addVehicleRequest.getRegisterDate());
        vehicle.setFileNum(addVehicleRequest.getFileNum());
        vehicle.setApprovedCount(addVehicleRequest.getVehicleWeightLimits());
        vehicle.setTotalMass(addVehicleRequest.getTotalMass());
        vehicle.setMaintenanceMass(addVehicleRequest.getMaintenanceMass());
        if (addVehicleRequest.getPermittedTowWeight() != null) {
            vehicle.setPermittedTowWeight(addVehicleRequest.getPermittedTowWeight());
        }
        vehicle.setPermittedWeight(addVehicleRequest.getVehicleWeightLimits());
        vehicle.setVehLength(addVehicleRequest.getVehicleLong());
        vehicle.setVehWidth(addVehicleRequest.getVehicleWidth());
        vehicle.setVehHeight(addVehicleRequest.getVehicleHeight());
        //车轮数和车轴数暂时写死
        vehicle.setWheelCount(4);
        vehicle.setAxleCount(2);
        vehicle.setAxleDistance(addVehicleRequest.getVehicleWheelBases());
        vehicle.setAxisType(addVehicleRequest.getAxisType());
        //车辆特征描述用车辆品牌型号填充
        vehicle.setVehFeature(addVehicleRequest.getVehicleSpecificInformation());

        //以下三个字段暂时无法同步信息
        vehicle.setOwnerTel("");
        vehicle.setOwnerName("");
        vehicle.setContact("");
        return vehicle;
    }

    public static AddVehicleRequest translate(CarInfo vehicle) {
        AddVehicleRequest addVehicleRequest = new AddVehicleRequest();
        addVehicleRequest.setUserId(vehicle.getUserId());
        addVehicleRequest.setVehiclePlate(vehicle.getVehPlate());
        addVehicleRequest.setVehiclePlateColor(vehicle.getVehColor());
        addVehicleRequest.setVehicleType(vehicle.getType());
        addVehicleRequest.setIdNum(vehicle.getOwnerIdNum());
        addVehicleRequest.setCsUserNo(vehicle.getCsUserNo());
        addVehicleRequest.setCarType(vehicle.getVehicleType());
        addVehicleRequest.setVehicleSpecificInformation(vehicle.getVehicleModel());
        if (vehicle.getUseCharacter() == 1) {
            addVehicleRequest.setCardUserType(0);
        } else {
            addVehicleRequest.setCardUserType(vehicle.getUseCharacter());
        }
        addVehicleRequest.setVin(vehicle.getVin());
        addVehicleRequest.setVehicleEngineNumber(vehicle.getEngineNum());
        addVehicleRequest.setIssueDate(vehicle.getIssueDate());
        addVehicleRequest.setRegisterDate(vehicle.getRegisterDate());
        addVehicleRequest.setFileNum(vehicle.getFileNum());
        addVehicleRequest.setVehicleWeightLimits(vehicle.getApprovedCount());
        addVehicleRequest.setTotalMass(vehicle.getTotalMass());
        addVehicleRequest.setMaintenanceMass(vehicle.getMaintenanceMass());
        if (vehicle.getPermittedTowWeight() != null) {
            addVehicleRequest.setPermittedTowWeight(vehicle.getPermittedTowWeight());
        }
        addVehicleRequest.setVehicleLong(vehicle.getVehLength());
        addVehicleRequest.setVehicleWidth(vehicle.getVehWidth());
        addVehicleRequest.setVehicleHeight(vehicle.getVehHeight());
        addVehicleRequest.setVehicleWheelBases(vehicle.getAxleDistance());
        addVehicleRequest.setAxisType(vehicle.getAxisType());
        //车辆特征描述用车辆品牌型号填充
        addVehicleRequest.setVehicleSpecificInformation(vehicle.getVehicleModel());

        //车轮数和车轴数暂时写死
        addVehicleRequest.setVehicleWheels(4);
        addVehicleRequest.setVehicleAxles(2);

        //以下三个字段暂时无法同步信息
//        vehicle.setOwnerTel("");
//        vehicle.setOwnerName("");
//        vehicle.setContact("");
        return addVehicleRequest;
    }
}
